home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
SAMPLES
/
MISCCMDS.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
16KB
|
677 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 012290 : Initial
*/
#include <SoundMgr.h>
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
/*******************************************************************/
Boolean DoECHO( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
int16 i, argc, newline = TRUE;
char *cp, argument[ 256 ];
(**MyShell).Proc[ ProcID ].flags = TRUE;
argc = (**MyShell).Proc[ ProcID ].argc;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'n' :
newline = FALSE;
break;
}
}
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ != '-' )
{
cp = argument;
while( *cp ) cp++;
*cp++ = ' '; /* add a space */
*cp++ = '\0';
StdOut( ShellWh, ProcID, argument );
}
}
if( newline )
StdOut( ShellWh, ProcID, "\n" );
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}
/*******************************************************************/
Boolean DoSOUND( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
int16 i, argc, s=-1, doBeep = TRUE;
char *cp, argument[ 256 ];
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 's' : /* silent operation */
doBeep = FALSE;
break;
}
}
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
{
GetArgv( ShellWh, ProcID, 1, argument );
CtoPstr( argument );
if( GoodNum( argument ) )
{
PtoCstr( argument );
s = *argument - '0';
if( s > 7 )
s = 7;
if( s < 0 )
s = 0;
SetSoundVol(s);
if( doBeep )
SysBeep( 1 );
}
}
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( TRUE );
}
}
}
/*******************************************************************/
DateTimeRec myTime;
GetShellDate( char *buf )
{
GetTime( &myTime );
sprintf( buf, "%02.0d/%02.0d/%4.0d" ,myTime.month,
myTime.day,myTime.year);
}
GetShellTime( char *buf )
{
GetTime( &myTime );
sprintf( buf, "%02.0d:%02.0d:%02.0d",myTime.hour,
myTime.minute,myTime.second );
}
/*******************************************************************/
Boolean DoDATE( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
{
ShellWindRec **MyShell;
char buf[ 32 ];
MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
GetShellDate( buf );
procPrintf( ShellWh, ProcID, "Date %s\n", buf );
GetShellTime( buf );
procPrintf( ShellWh, ProcID, "Time %s\n", buf );
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}
/*******************************************************************/
static int16 days_per_month[12]=
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,};
static char *mname[]=
{
"illegal month",
"January",
"Feburary",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
static int16 doy[]={ 999,0,31,59,90,120,151,181,212,243,273,304,334 };
char *monthn( int16 n )
{
return((n<1 || n>12) ? mname[0]: mname[n]);
}
int16 day( int16 month, int16 year )
{
int16 leapdtd;
int16 dayown;
if ( year < 4 )
leapdtd=0;
else if (( month == 2 ) || ( month == 1 ))
leapdtd = ( year - 1 ) / 4;
else leapdtd = year / 4;
dayown = ( year + doy[ month ] - 1 + leapdtd ) %7;
return( dayown );
}
/*******************************************************************/
DumpCal( WHandle ShellWh, int16 ProcID, int16 month, int16 year )
{
int16 i, r;
int16 temp,tempmonth,tempLY=0;
if( (month>12) || (month <1) || (year>9999) || (year <1))
return;
if( year < 100 )
year += 1900;
procPrintf( ShellWh, ProcID, "\n%10s", monthn( month ) );
procPrintf( ShellWh, ProcID, " %d\n", year );
temp = day( month,year );
procPrintf( ShellWh, ProcID, "--------------------\n");
procPrintf( ShellWh, ProcID, "Su Mo Tu We Th Fr Sa\n");
for (i=1; i<=temp; i++)
procPrintf( ShellWh, ProcID, " ");
for (i=1; i<=(7-temp); i++)
procPrintf( ShellWh, ProcID, "%2d ",i);
procPrintf( ShellWh, ProcID, "\n");
if ((( year % 4 == 0 && year % 100 != 0) || year %400 ==0 ) && month == 2)
tempLY=1;
tempmonth = (days_per_month[ month-1 ]) + tempLY;
for( r = i; r <= tempmonth; r++ )
{
if ( ((temp+r)%7) )
procPrintf( ShellWh, ProcID, "%2d ",r);
else
procPrintf( ShellWh, ProcID, "%2d\n",r);
}
procPrintf( ShellWh, ProcID, "\n\n" );
}
/*******************************************************************/
Boolean DoCAL( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
{
int16 i, argc;
char *cp, argument[ 256 ];
int32 t;
int16 month, year;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
argc = (**MyShell).Proc[ ProcID ].argc;
switch( argc )
{
case 1 : /* cal for this month */
GetTime( &myTime );
DumpCal( ShellWh, ProcID, myTime.month, myTime.year );
break;
case 2 : /* cal for given year */
GetArgv( ShellWh, ProcID, 1, argument );
CtoPstr( argument );
if( GoodNum( argument ) )
{
StringToNum( argument, &t );
for( i = 1; i < 13; i++ )
{
if( UserAbort() )
break;
DumpCal( ShellWh, ProcID, i, (int16) t );
}
}
break;
case 3 : /* cal for given month/year */
GetArgv( ShellWh, ProcID, 1, argument );
CtoPstr( argument );
if( GoodNum( argument ) )
{
StringToNum( argument, &t );
month = (int16) t;
GetArgv( ShellWh, ProcID, 2, argument );
CtoPstr( argument );
if( GoodNum( argument ) )
{
StringToNum( argument, &t );
year = (int16) t;
DumpCal( ShellWh, ProcID, month, year );
}
}
break;
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}
/*******************************************************************
*
* Function PLAY
*
* PathName Callback function
*
* usage PLAY [options] [files]
*
*
*******************************************************************/
extern int16 appResFile;
#define doPlayID (**MyShell).Proc[ProcID].bflags.f0
#define listIDs (**MyShell).Proc[ProcID].bflags.f1
#define playAbort (**MyShell).Proc[ProcID].bflags.f2
#define playID (**MyShell).Proc[ProcID].options
void PLAYCallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
pathType what, int16 vRefNum, int32 dirID )
{
Handle sndHandle;
SndChannelPtr myChan = 0L;
int16 fileRefNum, num, index, id, playHead = TRUE,
resFileWasOpen = FALSE;
int32 type;
OSErr err;
char str[ 64 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
if( UserAbort() )
playAbort = TRUE;
if( playAbort )
return;
if( what == pathIsFile )
{
strcpy( str, last );
CtoPstr( str );
SetWD( vRefNum, dirID );
SetResLoad( FALSE );
if( ResFileOpen( last, vRefNum, dirID, &fileRefNum ) )
resFileWasOpen = TRUE;
else
fileRefNum = OpenResFile( str );
if( fileRefNum == (-1) )
return;
UseResFile( fileRefNum );
if( doPlayID )
{
sndHandle = Get1Resource( 'snd ', (int16) playID );
if( sndHandle )
{
if( listIDs )
{
if( playHead )
{
sprintf( str, "%s:%s", path, last );
MacToPath( str );
procPrintf( ShellWh, ProcID, "play : %s\n", str );
playHead = FALSE;
}
GetResInfo( sndHandle, &id, &type, str );
procPrintf( ShellWh, ProcID, " : ID %5d NAME %ps\n", id, str );
}
LoadResource( sndHandle );
SndPlay( myChan, sndHandle, FALSE );
ReleaseResource( sndHandle );
}
if( err = ResError() )
procPrintf( ShellWh, ProcID, "play : resource error %d\n", err );
}
else
{
num = Count1Resources( 'snd ' );
for( index = 1; index <= num; index++ )
{
CheckFreeMem();
sndHandle = Get1IndResource( 'snd ', index );
if( sndHandle )
{
if( listIDs )
{
if( playHead )
{
sprintf( str, "%s:%s", path, last );
MacToPath( str );
procPrintf( ShellWh, ProcID, "play : %s\n", str );
playHead = FALSE;
}
GetResInfo( sndHandle, &id, &type, str );
procPrintf( ShellWh, ProcID, " : ID %5d NAME %ps\n", id, str );
}
LoadResource( sndHandle );
SndPlay( myChan, sndHandle, FALSE );
ReleaseResource( sndHandle );
}
if( err = ResError() )
{
procPrintf( ShellWh, ProcID, "play : resource error %d\n", err );
break;
}
}
}
if( !resFileWasOpen )
CloseResFile( fileRefNum );
SetResLoad( TRUE );
UseResFile( appResFile );
}
}
/*******************************************************************/
void PLAYFile( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
ExpandPath( ShellWh, ProcID, argument, (ProcPtr) PLAYCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoPLAY( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
{
int16 i, argc, hasNoFile = TRUE;
char *cp, argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
playAbort = TRUE;
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
doPlayID = FALSE;
listIDs = FALSE;
playAbort = FALSE;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'i' : /* next is ID */
GetArgv( ShellWh, ProcID, i+1, argument );
CtoPstr( argument );
StringToNum( argument, &playID );
doPlayID = TRUE;
break;
case 'v' : /* list snd ids */
listIDs = TRUE;
break;
}
}
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( (*argument == '-') && (argument[1] == 'i') )
i++;
else if( *argument != '-' )
{
hasNoFile = FALSE;
PLAYFile( ShellWh, ProcID, argument );
}
}
if( hasNoFile )
SysBeep( 1 );
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}